refract_time=100;
min_dur=50;

p_sac=ones(2000,1);
p_ps=ones(2000,1);
do_layer=2;
cnt=0;

for ind=1:length(AV_data)
    if AV_data(ind).layer==do_layer & AV_data(ind).ACode==1
        ind
        saccade_times=AV_data(ind).iframe_times(AV_data(ind).saccade_frames);
        
        [ps_raw]=find_ps_during_running(AV_data(ind).velP_ind,AV_data(ind).velM_ind);
        [ps_start]=parse_cond_starts(ps_raw,min_dur,refract_time);
        
        for lnd=1:size(AV_data(ind).raw_act,2)
            cnt=cnt+1;
            
            ps_cell_cnt=0;
            ps_cell_snips_pre=[];
            ps_cell_snips_post=[];
            
            for knd=1:length(ps_start)
                [~,curr_frame]=min(abs(ps_start(knd)-AV_data(ind).frame_times));
                if curr_frame>20 & curr_frame<(length(AV_data(ind).frame_times)-20)
                    ps_cell_cnt=ps_cell_cnt+1;
                    ps_cell_snips_pre(:,ps_cell_cnt)=(AV_data(ind).raw_act(curr_frame-20:curr_frame-1,lnd));
                    ps_cell_snips_post(:,ps_cell_cnt)=(AV_data(ind).raw_act(curr_frame+1:curr_frame+20,lnd));
                end
            end
            
            if mean(ps_cell_snips_post(:))>mean(ps_cell_snips_pre(:))
                [p_ps(cnt),~]=ranksum(ps_cell_snips_post(:),ps_cell_snips_pre(:));
            end
            
            
            
            sac_cell_cnt=0;
            sac_cell_snips_pre=[];
            sac_cell_snips_post=[];
            for knd=1:length(saccade_times)
                [~,curr_frame]=min(abs(saccade_times(knd)-AV_data(ind).frame_times));
                if curr_frame>20 & curr_frame<(length(AV_data(ind).frame_times)-20)
                    sac_cell_cnt=sac_cell_cnt+1;
                    sac_cell_snips_pre(:,sac_cell_cnt)=(AV_data(ind).raw_act(curr_frame-20:curr_frame-1,lnd));
                    sac_cell_snips_post(:,sac_cell_cnt)=(AV_data(ind).raw_act(curr_frame+1:curr_frame+20,lnd));
                end
            end
             if mean(sac_cell_snips_post(:))>mean(sac_cell_snips_pre(:))
                [p_sac(cnt),~]=ranksum(sac_cell_snips_post(:),sac_cell_snips_pre(:));
            end
        end
    end
end        